const Generator = require('yeoman-generator');

module.exports = class extends Generator {
  prompting() {// 询问
    return this.prompt([
      {
        type: 'input',
        name: 'name',
        message: 'Your project name?',
        default: this.appname
      },
      {
        type: 'input',
        name: 'title',
        message: 'Your project title?',
        default: '****'
      }
    ])
      .then(answers => {
        this.answers = answers
      })
  }
  writing() {
    // 把每个文件通过模板转换到目标路径
    // 模板文件存放在templates文件夹中
    const templates = [
      'css/module.css',
      'js/module.js',
      'vue/module.vue',
      'module.html'
    ];

    templates.forEach(item => {
      this.fs.copyTpl(
        this.templatePath(item),
        this.destinationPath(`src/${item}`),
        this.answers
      )
    })
  }
}